﻿
package HG.Visual
{
	import flash.display.*;
	import flash.events.*;
	
	import fl.transitions.Tween;
	import fl.transitions.easing.*;
	import fl.transitions.TweenEvent;
	
	public class VisualCameraCanvas extends MovieClip
	{
		var m_posLocked:Boolean;
		
		//----------------------------------------------------------------------------------------------------
		public function VisualCameraCanvas()
		{
			m_posLocked = false;
			
			this.addEventListener(MouseEvent.MOUSE_DOWN, OnPress);
			this.addEventListener(MouseEvent.MOUSE_UP, OnRelease);
			
			this.addEventListener(MouseEvent.ROLL_OUT, OnRelease);
		}
		
		//----------------------------------------------------------------------------------------------------
		protected function OnPress(e:Event)
		{
			if (m_posLocked)
				return;
				
			this.startDrag(false);
		}
		
		//----------------------------------------------------------------------------------------------------
		protected function OnRelease(e:Event)
		{
			this.stopDrag();
		}
		
		//----------------------------------------------------------------------------------------------------
		public function LockPosition(lock:Boolean)
		{
			if (lock)
				this.stopDrag();
				
			m_posLocked = lock;
		}
		
		//----------------------------------------------------------------------------------------------------
		public function SetPosition(x:Number, y:Number)
		{
			if (m_posLocked)
				return;
			
			new Tween(this, "x", Strong.easeInOut, this.x, x, 2, true);
			new Tween(this, "y", Strong.easeInOut, this.y, y, 2, true);
		}
	}
}